package com.hecai.scanning.websocket;

import com.hecai.scanning.vo.NotifyMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2018/11/26.
 */
@Component
public class MessageComponent
{

    @Autowired
    private SimpMessagingTemplate template;

    /**
     * 广播
     * 发给所有在线用户
     *
     * @param msg
     */
    public void sendMsg(NotifyMessage msg)
    {
        template.convertAndSend(WebSocketConstant.PRODUCERPATH, msg);
    }

    /**
     * 发送给指定用户
     *
     * @param userName
     * @param msg
     */
    public void send2Users(String userName, NotifyMessage msg)
    {
        template.convertAndSendToUser(userName, WebSocketConstant.P2PPUSHPATH, msg);
    }
}
